package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2024-06-04
 * Time: 22:10
 */
public class ReturnBooks implements IBooks{
    @Override
    public void work(BookList booklist) {
        int count = booklist.getUsedSize();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还书籍的名字：:");
        String name = scanner.nextLine();
        int tmp = -1;
        for (int i = 0; i < count; i++) {
            Book book = booklist.getBook(i);
            if(book.getName().equals(name)){
                tmp = i;
                break;
            }
        }
        if(tmp == -1){
            System.out.println("图书馆没有该图书");
            return;
        }
        Book book2 = booklist.getBook(tmp);
        book2.setBorrowed(false);
        System.out.println("图书归还成功！");
    }
}
